//
//  MainViewController.m
//  VoSAT
//
//  Created by 王译 on 2018/4/22.
//  Copyright © 2018年 王. All rights reserved.
//

#import "MainViewController.h"

@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addChildViewControllers];
    // Do any additional setup after loading the view.
}
-(void)addChildViewControllers
{
    NSArray *array=@[
                     @{@"clsName":@"RecordViewController",@"title":@"通话记录",@"imageName":@"记录"},
                     @{@"clsName":@"FriendViewController",@"title":@"联系人",@"imageName":@"朋友"},
                  @{@"clsName":@"MsgViewController",@"title":@"短信",@"imageName":@"短信"},
                  @{@"clsName":@"MineViewController",@"title":@"我",@"imageName":@"我的"},
                     ];
    
    for (int i=0; i<array.count; i++) {
        UIViewController *vc = [self viewControllerWithDict:array[i]];
        [self addChildViewController:vc];
    }
    
}
-(UIViewController*)viewControllerWithDict:(NSDictionary*)dict {
    
    // 1. 初始化控制器
    UIViewController *vc = [NSClassFromString(dict[@"clsName"]) new];
    // 2. 设置标题 = 导航栏标题+tabbar的标题
    vc.title = dict[@"title"];
    // 3. 设置不同状态下显示的图片
//    vc.tabBarItem.image = [UIImage imageNamed:[NSString stringWithFormat:@"tabbar-%@-normal1", dict[@"imageName"]]];
    vc.tabBarItem.image = [UIImage imageNamed:dict[@"imageName"]];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:dict[@"imageName"]];
    
    // 使用导航控制器包裹该控制器并返回
    UINavigationController * nv = [[UINavigationController alloc] initWithRootViewController:vc];
    
    //    [fv.navigationBar setBarTintColor:[UIColor blueColor]];
    return nv;
    
    
    // return [[UINavigationController alloc]initWithRootViewController:vc];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
